// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/silicon_creator/rom_ext/imm_section/imm_section_version.h"

/*
 * Load stamp variables and set default values when building without --stamp
 */
#include "rules/autogen_stamp_include.inc"
#ifndef BAZEL_BUILD_SCM_REVISION_SHORT
#define BAZEL_BUILD_SCM_REVISION_SHORT 00000000
#endif
#ifndef BAZEL_BUILD_SCM_STATUS
#define BAZEL_BUILD_SCM_STATUS clean
#endif

/*
 * Map scm status to single char.
 */
#define SCM_INDICATOR_modified '+'
#define SCM_INDICATOR_clean ' '
#define SCM_INDICATOR OT_CAT(SCM_INDICATOR_, BAZEL_BUILD_SCM_STATUS)

/*
 * The version struct is stored at the end of imm_section.
 *
 * These values are generated by bazel and populated with C defines.
 */
OT_USED
OT_SECTION(".imm_section_version")
const imm_section_version_t imm_section_version = {
    .magic = kImmVersionMagic,
    .major = IMM_SECTION_MAJOR_VERSION,
    .minor = IMM_SECTION_MINOR_VERSION,
    // We cannot record clean/modified status because this affects build
    // reproducibility during ROM_EXT signing.
    //
    // During a signing ceremony:
    // - First we generate pre-signing artifacts, typically in a clean codebase.
    // - Next, we take hashes of the pre-signing artifacts offline and sign them
    //   with our signing infrastructure.
    // - Finally, we bring the offline signatures back to the codebase and land
    //   them in an appropriate `signatures` subdirectory.  This modifies the
    //   codebase, which then causes a change in the build_status value, which
    //   causes bazel to rebuild pre-signing artifacts, which invalidates the
    //   signatures.
    .build_status = SCM_INDICATOR_clean,
    .commit_hash = OT_CAT(0x0, BAZEL_BUILD_SCM_REVISION_SHORT),
};
